{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "36206d55-ba8e-451a-be9b-43590568122d",
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "from tqdm import tqdm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "245927b4-ae98-412f-8cdb-b9ade3e77e07",
   "metadata": {},
   "outputs": [],
   "source": [
    "f = open('./coco/coco_val_localized_narratives.jsonl',)\n",
    "count = 0\n",
    "same = 0\n",
    "l = []\n",
    "prefix = './coco/val2017/'\n",
    "for i in f:\n",
    "    img = json.loads(i)\n",
    "    img_id = img['image_id']\n",
    "    text_file_name = prefix + '%.12d'%int(img_id) + '.txt'\n",
    "    txt_file = open(text_file_name, 'a+')\n",
    "    txt_file.write(img['caption'] + '.\\n')\n",
    "    txt_file.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "abdb53e7-8f1e-4c94-836e-f6fe9d9a86c8",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 4/4 [1:32:33<00:00, 1388.45s/it]\n"
     ]
    }
   ],
   "source": [
    "for j in tqdm(range(4)):\n",
    "    f = open('./coco/coco_train_localized_narratives-0000%i-of-00004.jsonl'%j,)\n",
    "    count = 0\n",
    "    same = 0\n",
    "    l = []\n",
    "    prefix = './coco/train2017/'\n",
    "    for i in f:\n",
    "        img = json.loads(i)\n",
    "        img_id = img['image_id']\n",
    "        text_file_name = prefix + '%.12d'%int(img_id) + '.txt'\n",
    "        txt_file = open(text_file_name, 'a+')\n",
    "        txt_file.write(img['caption'] + '.\\n')\n",
    "        txt_file.close()\n",
    "        count += 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ef76e072-6022-4d4c-ad05-440a4747ed1d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
